package com.app.base.service.core.company.service.impl;

import com.app.base.service.auth.entity.SysUser;
import com.app.base.service.auth.service.SysUserService;
import com.app.base.service.core.company.entity.Company;
import com.app.base.service.core.company.mapper.CompanyMapper;
import com.app.base.service.core.company.service.CompanyService;
import com.app.base.utlis.result.Result;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author yuhag
 * @since 2022-05-09
 */
@Service
@Slf4j
public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> implements CompanyService {

    @Resource
    private SysUserService userService;

    @Override
    public Result companyInfo(String userId) {
        try{
            SysUser user = userService.getById(userId);
            Company company = baseMapper.selectById(user.getCompanyId());
            return Result.ok(company);
        }catch(Exception e){
            log.error(e.getMessage());
            return Result.error(e.getMessage());
        }
    }
}
